<%@ page
	import="java.util.*,com.db.tracker.vo.*,java.util.*,com.db.tracker.util.*,java.text.*,java.io.*"%>
<%@ page import="com.db.tracker.vo.ReleaseVO"%>
<%
		try {
		System.out.println("XXXXXXXXXXXXXXXXX START LOADING JSP PAGE XXXXXXXXXXXXXXXX");
		session = request.getSession();
		//		System.out.println("user_id..main"+ session.getAttribute("USER_ID"));

		if (session.getAttribute("USER_ID") == null || !((String) session.getAttribute("SESSION_ID")).equals(session.getId())) {

			try {
				response.sendRedirect("LoginPage.jsp");
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}

		} else {
			
			String userid = (String) session.getAttribute("USER_ID") == null ? "" : (String) session.getAttribute("USER_ID");
			DBUtil dbutil = new DBUtil(getServletContext());
			
			
			int DataServerID = Integer.parseInt(request.getParameter("DataServerID") == null ? "0" : request.getParameter("DataServerID"));
			DBServerBean serverBean = new DBServerBean();
			serverBean = dbutil.getDataServerInfo(DataServerID);

			String UpdateButton = request.getParameter("UpdateServerInfoBtn") == null ? "" : request.getParameter("UpdateServerInfoBtn");
			String DeleteButton = request.getParameter("DeleteServerInfoBtn") == null ? "" : request.getParameter("DeleteServerInfoBtn");
%>
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
<title>Update Data Server Information...</title>
<script>
	function checkForEmpty(DataServer,IP,NYShortPath,LNShortPath,RefreshFreq,DBsRefreshed,DataserverHost){
		  	
					// alert("obj.value.length"+obj.value);
			
				DataServer.value = trim(DataServer.value);
				IP.value = trim(IP.value);
				NYShortPath.value = trim(NYShortPath.value);
				LNShortPath.value = trim(LNShortPath.value);
				RefreshFreq.value = trim(RefreshFreq.value);
				DBsRefreshed.value = trim(DBsRefreshed.value);
				DataserverHost.value = trim(DataserverHost.value);
	
				if (DataServer.value.length == 0 )
				{
					alert("Please enter Data Server Name");
					DataServer.focus();
					return false;
				}
				if (DataserverHost.value.length == 0 )
				{
					alert("Please enter Data Server Host Name");
					DataserverHost.focus();
					return false;
				}
				if (IP.value.length == 0 )
				{
					alert("Please enter IP address");
					IP.focus();
					return false;
				}
				if (NYShortPath.value.length == 0 )
				{
					alert("Please enter NY Shortcut Path");
					NYShortPath.focus();
					return false;
				}
				if (LNShortPath.value.length == 0 )
				{
					alert("Please enter LN Shortcut Path");
					LNShortPath.focus();
					return false;
				}
				if (RefreshFreq.value.length == 0 )
				{
					alert("Please enter Refresh Freq.");
					RefreshFreq.focus();
					return false;
				}
				if (DBsRefreshed.value.length == 0 )
				{
					alert("Please enter name of databases refreshed");
					DBsRefreshed.focus();
					return false;
				}

			//	document.EditDataServerInfoForm.submit();
				
		} 				

		function trim(sString)
			{
				sTrimmedString = "";
			   if (sString != "") {
				  var iStart = 0;
				  var iEnd = sString.length - 1;	
				  // var sWhitespace = " \t\f\n\r\v";
				  var sWhitespace = "   ";
		
	
				  while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
				  iStart++;
				  if (iStart > iEnd) 
					break;
			   }

			  // If the string not just whitespace
			  if (iStart <= iEnd) {
				 while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
					iEnd--;
				 sTrimmedString = sString.substring(iStart,++iEnd);
			  }
		   }
		   return sTrimmedString;
		 }


		</script>
</head>

<body>

<!-- 
<form name="updateRelease" method="post">
<table width=100%>
	<tr>
		<td width=100%><jsp:include page="HeaderNav_ReleaseObject.jsp" />
		</td>
	</tr>
</table>
</form>
 -->

<%
			//		System.out.println(">>>> Updatebutton :"+UpdateButton);
			if (UpdateButton.equals("Update")) {
				boolean updateSuccessFlag = false;
		
				String DataServer = request.getParameter("DataServer") == null ? "" : request.getParameter("DataServer");
				String IP = request.getParameter("IP") == null ? ""	: request.getParameter("IP");
				String NYShortPath = request.getParameter("NYShortPath") == null ? ""	: request.getParameter("NYShortPath");
				String LNShortPath = request.getParameter("LNShortPath") == null ? "" : request.getParameter("LNShortPath");
				String RefreshFreq = request.getParameter("RefreshFreq") == null ? "" : request.getParameter("RefreshFreq");
				String DataserverHost = request.getParameter("DataserverHost") == null ? "" : request.getParameter("DataserverHost");
				String DBsRefreshed = request.getParameter("DBsRefreshed") == null ? "" : request.getParameter("DBsRefreshed");
				String Remarks = request.getParameter("Remarks") == null ? "" : request.getParameter("Remarks");

				int hiddenDataServerID = Integer.parseInt(request.getParameter("hiddenDataServerID") == null ? "0" : request.getParameter("hiddenDataServerID"));

				updateSuccessFlag = dbutil.updateDataServerInfo(DataServer, IP, NYShortPath, LNShortPath, RefreshFreq, Remarks, DataserverHost, DBsRefreshed, userid, hiddenDataServerID);

				if(updateSuccessFlag == true){
%>
						<script>
							alert("Data Server Details updated successfully.");
							window.opener.location.href="/st/AdminDataServerInfo.jsp";
							window.close();
						</script>

<%		}else{
	%> 
						<script>
							alert("Error while updating data server info.");
							window.close();
						</script>
	
	<% 
			}
	}
			if (DeleteButton.equals("Delete")) {

				int hiddenDataServerID = Integer.parseInt(request.getParameter("hiddenDataServerID") == null ? "0" : request.getParameter("hiddenDataServerID"));
				dbutil.deleteDataServerInfo(hiddenDataServerID);
%>
						<script>
							alert("Data server info deleted successfully.");
							window.opener.location.href="/st/AdminDataServerInfo.jsp";
							window.close();
						</script>

<%
}
%>




<form name="EditDataServerInfoForm" action="EditDataServerInfo.jsp" method="post">

<table cellpadding="0" cellspacing="1" width="75%" style="BORDER:#000000 1px solid" align='center' colspan=2>
	<input type="hidden" name="hiddenDataServerID" value="<%= serverBean.getDataServerID() %>">
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=2><b>Edit Data Server Information</b></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Data Server Name</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="DataServer" size="40" value='<%= serverBean.getDataServer() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Dataserver Host Name</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="DataserverHost" size="40" value='<%= serverBean.getDataServerHost() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">IP Address</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="IP" size="40" value='<%= serverBean.getIP() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">NY Shortcut Path</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="NYShortPath" size="40" value='<%= serverBean.getNYShortPath() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">LN Shortcut Path</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="LNShortPath" size="40" value='<%= serverBean.getLNShortPath() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Refresh (Freq)</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="RefreshFreq" size="40" value='<%= serverBean.getRefreshFreq() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Databases Refreshed</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="DBsRefreshed" size="40" value='<%= serverBean.getDBsRefreshed() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Remarks</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="Remarks" size="40" value='<%= serverBean.getRemarks() %>'>
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td colspan="1" class="bodyblue" width="30%">&nbsp</td>
		<td colspan="1" class="bodyblue" width="70%">&nbsp</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class="bodyblue" colspan="1" width="50%" align=right>
		<input
			type=submit class=whitebutton name=UpdateServerInfoBtn
			value="Update" onclick="return checkForEmpty(DataServer,IP,NYShortPath,LNShortPath,RefreshFreq,DBsRefreshed,DataserverHost)">
			</td>
		<td class="bodyblue" colspan="1" width="50%" align=right>
		<input
			type=submit class=whitebutton name=DeleteServerInfoBtn
			value="Delete"></td>
	</tr>

</table>
</form>


</body>
</html>

<%
	}
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
